<template>
	<view class="fatherView">
		<view class="searchBox">
			<my-search @myClick="goSearch"></my-search>
		</view>
		<swiper class="swiper" indicator-dots="true" autoplay="true" circular="true">
			<swiper-item v-for="item in swiperList" :key="item.goods_id">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
					<image class="swiperImage" :src="item.image_src"></image>
				</navigator>
				<!-- <image class="swiperImage" :src="item.image_src"></image> -->
			</swiper-item>
		</swiper>
		<view class="middleNavView">
			<view class="navView" v-for="(item,index) in middleNavs" :key="index" @click="navClick(item)">
				<image class="navImage" :src="item.image_src"></image>
				<!-- <div class="navText">{{item.name}}</div> -->
			</view>
		</view>
		<view class="floorView">
			<view class="floorItem" v-for="(item,index) in floorList" :key="index">
				<image class="floorTitleImage" :src="item.floor_title.image_src"></image>
				<view class="floor-img-box">
					<navigator class="left-img-box" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
					</navigator>
					<view class="right-img-box">
						<navigator class="right-img-item" v-for="(item2,index2) in item.product_list" :key="index2" :url="item2.url">
							<image :src="item2.image_src" v-if="index2 !== 0" :style="{width:item2.image_width +'rpx'}" mode="widthFix"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	
	export default {
		mixins: [badgeMix],
		data() {
			return {
				swiperList: [],
				middleNavs: [],
				floorList: []
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getMiddleNavs()
			this.getFloorList()
		},
		methods: {
			async getSwiperList() {
				const {data: res} = await uni.$http.get('/home/swiperdata')
				if (res.meta.status !== 200) {
					return uni.$showErrMsg()
					// return uni.showToast({
					// 	title: '数据请求失败',
					// 	duration: 1500,
					// 	icon: 'none'
					// })
				}
				this.swiperList = res.message
				return uni.$showErrMsg('数据请求成功')
			},
			async getMiddleNavs() {
				const {data : res} = await uni.$http.get('/home/catitems')
				if (res.meta.status !== 200) return uni.$showErrMsg()
				this.middleNavs = res.message
			},
			async getFloorList() {
				const {data: res} = await uni.$http.get('/home/floordata')
				console.log(res)
				if (res.meta.status !== 200) return uni.$showErrMsg()
				//对数据进行处理
				res.message.forEach(floor=>{
					floor.product_list.forEach(flood=>{
						flood.url = '/subpkg/goods_list/goods_list?'+flood.navigator_url.split('?')[1]
					})
				})
				this.floorList = res.message
			},
			navClick(item){
				console.log(item)
				if (item.name == '分类') {
					uni.switchTab({
						url:'/pages/cate/cate'	
					})
				}
			},
			goSearch(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
	.fatherView{
		.searchBox{
			position: sticky;
			top: 0;
			z-index: 999;
		}
		.swiper{
			width: 100%;
			height: 300rpx;
			.swiper-item{
				height: 100%;
				height: 100%;
				.swiperImage{
					width: 100%;
					height: 100%;
				}
			}
		}
		.middleNavView{
			display: flex;
			width: 100%;
			height: 100px;
			justify-content: center;
			margin: 15rpx 0;
			.navView{
				width: 25%;
				height: 180rpx;
				.navImage{
					width: 160rpx;
					height: 100%;
				}
			}
		}
	}
	.floorView{	
		.floorItem{
			.floorTitleImage{
				width: 100%;
				height: 60rpx;
			}
			.floor-img-box{
				display: flex;
				padding-left: 10rpx;
				.right-img-box{
					display: flex;
					flex-wrap: wrap;
					justify-content: space-around;
				}
			}
		}
	}
	
</style>
